package cn.edu.lingnan.fruitshop.controller;


import cn.edu.lingnan.fruitshop.service.OrdertableService;
import com.alipay.api.AlipayApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张小凡
 * @since 2022-01-04
 */
@Controller
@RequestMapping("/ordertable")
public class OrdertableController {

    @Autowired
    private OrdertableService ordertableService;

    //点击提交订单后，创建订单

    /**
     *

     * @return
     */
    @GetMapping("/creatOrder")
    public String creatOrder(Model model,Integer orderId,Integer addressId,HttpSession session){
        return ordertableService.creatOrder(model,orderId,addressId,session);
    }
    @ResponseBody
    @GetMapping("/pay")
    public String pay(Model model,Integer orderId,Integer addressId,HttpSession session) throws AlipayApiException {
        return ordertableService.pay(model,orderId,addressId,session);
    }

    /**
     * 根据订单id把 订单详情和订单 删除掉
     * @param id
     * @return
     */
    @RequestMapping("/deleteOrder")
    public String deleteOrder(Model model, HttpSession session, Integer id, Integer currentPage){
        return ordertableService.deleteOrder(model,session,id,currentPage);
    }

}

